package cn.skyquant.quant4j.service.boot.web.config;

import cn.skyquant.quant4j.service.boot.model.authority.RoleAuthority;
import cn.skyquant.quant4j.service.boot.web.vo.MenuItemVO;
import cn.skyquant.quant4j.service.boot.web.vo.MenuVO;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class RoleMenuConfig {

    public static final Map<String, Set<MenuVO>> roleMenuMap = new HashMap<>();
    private static final MenuVO index = new MenuVO("首页","index.html","fa fa-home",(short)0);
    private static final MenuVO systeminfo = new MenuVO("系统信息","system.html","fa fa-user-circle",(short)1);
    private static final MenuVO userinfo = new MenuVO("个人信息","user.html","fa fa-user-circle",(short)1);
    private static final MenuVO account = new MenuVO("交易账户","account.html","fa fa-dollar",(short)3);
    private static final MenuVO fund = new MenuVO("基金情况","fund.html","fa fa-line-chart",(short)4);

    private static final MenuItemVO ea = new MenuItemVO("EA监控","ea.html");
    private static final MenuItemVO strategy_test = new MenuItemVO("策略测试","strategy_test.html");
    private static final MenuVO strategy = new MenuVO("策略管理",null,"fa fa-pie-chart",(short)5,ea,strategy_test);

    private static final MenuItemVO goods = new MenuItemVO("交易品种","goods.html");
    private static final MenuItemVO symbol = new MenuItemVO("货币组","forex_config.html?type=Symbol");
    private static final MenuItemVO series = new MenuItemVO("加仓数列","forex_config.html?type=Series");
    private static final MenuItemVO ylzc = new MenuItemVO("压力支撑位","ylzc.html");
    private static final MenuVO settings = new MenuVO("后台参数设置",null,"fa fa-cog",(short)7,goods,symbol,series,ylzc);

    private static final MenuItemVO economics = new MenuItemVO("财经事件","economics.html");
    private static final MenuItemVO forex = new MenuItemVO("外汇","forex.html");
    private static final MenuItemVO stock = new MenuItemVO("股票","black.html");
    private static final MenuVO market = new MenuVO("市场信息",null,"fa fa-bar-chart",(short)8,economics,forex);

    static {
        roleMenuMap.put(RoleAuthority.administrator, Sets.newHashSet(index,systeminfo,userinfo,fund,account,strategy,settings,market));
        roleMenuMap.put(RoleAuthority.client, Sets.newHashSet(index,userinfo,fund,account,market));
        roleMenuMap.put(RoleAuthority.user, Sets.newHashSet(index,userinfo,fund,market));
        roleMenuMap.put(RoleAuthority.guest,Sets.newHashSet(index,userinfo,fund,market));
    }

    public static List<MenuVO> getMenuByRole(final Set<String> roles){
        final Set<MenuVO> allRoles = Sets.newHashSet();
        roles.stream().forEach(x-> allRoles.addAll(roleMenuMap.get(x)));
        final List<MenuVO> menuVOList = Lists.newArrayList(allRoles);
        menuVOList.sort((a,b)-> a.sort - b.sort);
        return menuVOList;

    }
}
